﻿CREATE PROCEDURE [dbo].[yaf_poll_save](
                @Question NVARCHAR(50),
                @Choice1  NVARCHAR(50),
                @Choice2  NVARCHAR(50),
                @Choice3  NVARCHAR(50)  = NULL,
                @Choice4  NVARCHAR(50)  = NULL,
                @Choice5  NVARCHAR(50)  = NULL,
                @Choice6  NVARCHAR(50)  = NULL,
                @Choice7  NVARCHAR(50)  = NULL,
                @Choice8  NVARCHAR(50)  = NULL,
                @Choice9  NVARCHAR(50)  = NULL,
                @Closes   DATETIME  = NULL)
AS
    BEGIN
        DECLARE  @PollID INT
        INSERT INTO yaf_Poll
                   (Question,
                    Closes)
        VALUES     (@Question,
                    @Closes)
        SET @PollID = Scope_identity()
        IF @Choice1 <> ''
           AND @Choice1 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice1,
                    0)
        IF @Choice2 <> ''
           AND @Choice2 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice2,
                    0)
        IF @Choice3 <> ''
           AND @Choice3 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice3,
                    0)
        IF @Choice4 <> ''
           AND @Choice4 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice4,
                    0)
        IF @Choice5 <> ''
           AND @Choice5 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice5,
                    0)
        IF @Choice6 <> ''
           AND @Choice6 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice6,
                    0)
        IF @Choice7 <> ''
           AND @Choice7 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice7,
                    0)
        IF @Choice8 <> ''
           AND @Choice8 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice8,
                    0)
        IF @Choice9 <> ''
           AND @Choice9 IS NOT NULL
        INSERT INTO yaf_Choice
                   (PollID,
                    Choice,
                    Votes)
        VALUES     (@PollID,
                    @Choice9,
                    0)
        SELECT PollID = @PollID
    END


